package translationModel;


public class Sentence
{
	private String[] words;
	
	public Sentence(String str)
	{
		str = str.trim();
		words = str.split(" ");
	}
	
	public String getWord(int index)
	{
		if (index == -1 || index == -2)
			return "<s>";
		return words[index];
	}
	
	public String toString()
	{
		String str = "";
		for(int i=0;i<words.length;i++)
			str += " " + words[i];
		return str.trim();
	}
	
	public int length()
	{
		return words.length;
	}
	
	public int FindSubSentence(Sentence phrase)
	{
		return FindSubSentence(0, phrase);
	}
	
	public int FindSubSentence(int fromIndex, Sentence phrase)
	{
		for (int i = fromIndex; i < words.length - phrase.length() + 1; i++)
		{
			boolean foundDifferent = false;
			for (int j = 0; j < phrase.length(); j++)
			{
				if (!words[i + j].equalsIgnoreCase(phrase.getWord(j)))
				{
					foundDifferent = true;
					break;
				}
			}
			
			if (!foundDifferent)
				return i;
		}
		return -1;
	}
}
